

//
//  ClassTableView.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/19.
//  Copyright © 2016年 Gcx. All rights reserved.
//

#import "ClassTableView.h"
//#import "ClassDetailModel.h"
#import "DetailListTableViewCell.h"

@interface ClassTableView()<UITableViewDelegate, UITableViewDataSource>{

    
}

@end

@implementation ClassTableView


- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{

    if (self = [super initWithFrame:frame style:style]) {
                
        self.delegate = self;
        self.dataSource = self;
        
        self.rowHeight = 270*0.383*SIZEWIDTH/414;
        
//        [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        
        [self registerClass:[DetailListTableViewCell class] forCellReuseIdentifier:@"DetailListTableViewCell"];
        
        /**
         *  刷新加载
         */
        [self setupRefresh];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopRefresh) name:@"isClassListRefresh" object:nil];

    }
    return self;
}

- (void)stopRefresh{
    
    [self.mj_footer endRefreshing];
    [self.mj_header endRefreshing];
}

/**
 *  刷新加载
 */
- (void)setupRefresh{
    
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        [self.mj_header beginRefreshing];
        
        _myBlock(YES);
        
    }];
    header.stateLabel.textColor = COLOR_TITLE_999999;
    header.lastUpdatedTimeLabel.textColor = COLOR_TITLE_999999;
    self.mj_header = header;
    
    
    MJRefreshAutoNormalFooter * foot = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        [self.mj_footer beginRefreshing];
        
        _myBlock(NO);
        
    }];
    foot.stateLabel.textColor = COLOR_TITLE_999999;
    self.mj_footer = foot;
    
}

- (NSInteger)numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return  self.sourceArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DetailListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailListTableViewCell"];
    cell.myModel = _sourceArr[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.001;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([self.myDelegate respondsToSelector:@selector(classTableViewSeleted:resuletString:Row:)]) {
        
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        
        [self.myDelegate classTableViewSeleted:self resuletString:self.sourceArr[indexPath.row] Row:(int)indexPath.row];
    }
}

- (void)setSourceArr:(NSArray *)sourceArr{

    _sourceArr = sourceArr;
    
    [self reloadData];
}

@end
